"""
@author: xxw
@file: product.py
@time: 2023/7/31 21:06
"""
from . import db

# 歌曲表
class Song(db.Model):
    __tablename__ = "Song"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    song_name = db.Column(db.String(50))
    singer = db.Column(db.String(10))
    duration = db.Column(db.String(20))
    kind = db.Column(db.ForeignKey('Style.kind_id'))
    comment_count = db.Column(db.Integer)
    song_lyc = db.Column(db.String(2000))
    song_link = db.Column(db.String(2000))
    song_photo = db.Column(db.String(2000))

    # 实现可迭代
    def keys(self):
        return ('song_name','singer','kind','duration','comment_count')
    def __getitem__(self, item):
        if item == 'kind':
            return getattr(self.Kind, 'style')
        else:
            return getattr(self, item)

# 歌曲风格表
class Style(db.Model):
    __tablename__ = "Style"
    kind_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    style = db.Column(db.String(10))
    song_info = db.relationship("Song", backref="Kind")



